Popular Searches
Popular Course Categories
Popular Courses

Introduction to React and Component-Based Architecture

Introduction to React and Component-Based Architecture

React Fundamentals for React Native

Introduction to React and Component-Based Architecture

Course: React Native Training

Topic: Introduction to React and Component-Based Architecture

Course Link: React Native Training Course

Demo Registration: Register for a Free Course Demo

JustAcademy Website: Visit JustAcademy


1. Introduction to React

React is an open-source JavaScript library used to build user interfaces. It was developed by Meta and is widely used for creating interactive web applications. React allows developers to divide an application's user interface into small, reusable components.

React primarily focuses on the presentation layer of an application. It helps developers describe how the interface should look based on the application's data and state. When the data changes, React updates the relevant parts of the interface.

React is commonly used for web development, while React Native uses React concepts to build mobile applications for platforms such as Android and iOS.

1.1 What Is a User Interface?

A user interface (UI) is the part of an application that users see and interact with. It includes buttons, text, images, forms, navigation bars, menus, lists, and other visual elements.

For example, a shopping application may contain the following UI elements:

  • A header displaying the application name.
  • A search bar for finding products.
  • Product cards displaying images, names, and prices.
  • Buttons for adding products to a cart.
  • A navigation menu for switching between screens.

React helps developers organize these elements into reusable components instead of writing the entire interface as one large block of code.

1.2 Why Was React Introduced?

Traditional approaches to building interactive interfaces can become difficult to maintain when an application grows. Developers may need to update the DOM manually, repeat similar code, and keep multiple parts of the interface synchronized with application data.

React addresses these challenges through component-based development, declarative UI rendering, reusable logic, and state-driven updates.

1.3 Key Features of React

Feature Description Benefit
Component-Based Architecture Builds interfaces from independent, reusable components. Improves maintainability and code reuse.
Declarative UI Developers describe the desired interface for a given state. Makes UI logic easier to understand.
JSX A syntax extension that allows markup-like expressions in JavaScript. Helps organize UI structure and logic together.
Props Pass data from a parent component to a child component. Supports reusable and configurable components.
State Stores data that can change over time within a component. Allows interfaces to respond to user actions.
Hooks Functions such as useState and useEffect that enable React features in function components. Organizes state and side-effect logic.
Virtual DOM Concept React uses an in-memory representation of the UI to help determine updates. Helps React update the rendered interface efficiently.

2. Understanding React Native

React Native is a framework for building native mobile applications using JavaScript or TypeScript and React concepts. It allows developers to create Android and iOS applications while sharing a substantial amount of code between platforms.

React Native uses components such as View, Text, Image, and Pressable to create mobile interfaces. These components are different from HTML elements such as div and p.

2.1 React vs React Native

Basis React React Native
Primary Purpose Builds user interfaces, especially for the web. Builds native mobile applications.
Rendering Elements Uses DOM elements such as div, button, and input in web applications. Uses native-oriented components such as View, Text, and Pressable.
Styling Commonly uses CSS or CSS-in-JS solutions. Uses JavaScript style objects with a CSS-like subset of properties.
Navigation Often uses web routing libraries. Often uses mobile navigation libraries.
Platform Primarily browser-based interfaces. Primarily Android and iOS mobile applications.
Shared Concepts Components, props, state, hooks, and JSX. Components, props, state, hooks, and JSX.

2.2 How React Concepts Apply to React Native

React Native uses the same fundamental React programming model. Developers create components, pass data through props, manage changing values with state, and respond to user interactions with event handlers.

For example, a React web application might use a button element, while a React Native application may use Pressable. The components differ, but the underlying concepts of component composition and state-driven rendering remain similar.

3. What Is Component-Based Architecture?

Component-based architecture is a software design approach in which an application is divided into smaller, independent, and reusable building blocks called components. Each component is responsible for a specific part of the interface or functionality.

Instead of writing an entire application inside one large file or component, developers create smaller components and combine them to form complete screens and applications.

For example, a mobile shopping application can be divided into Header, SearchBar, ProductCard, ProductList, CartButton, and BottomNavigation components.

3.1 Definition of a Component

A component is a reusable unit of UI that can contain presentation, behavior, and logic. In modern React development, components are commonly written as JavaScript or TypeScript functions that return React elements, usually through JSX.

Example of a simple React function component:

function Welcome() {
  return <h1>Welcome to React!</h1>;
}

export default Welcome;

This example is intended for a React web application. In React Native, use native-oriented components instead of HTML elements.

React Native equivalent:

import React from 'react';
import { View, Text } from 'react-native';

function Welcome() {
  return (
    <View>
      <Text>Welcome to React Native!</Text>
    </View>
  );
}

export default Welcome;

The Welcome function is a component. It returns a UI structure that React Native can render on the mobile device.

3.2 Main Characteristics of Components

  • Reusability: A component can be used in multiple places.
  • Modularity: Each component focuses on a specific responsibility.
  • Composition: Components can be combined to create larger interfaces.
  • Encapsulation: Components can keep their internal implementation details separate from other components.
  • Configurability: Props allow components to display different content or behave differently.
  • Maintainability: Small, well-organized components are generally easier to understand, test, and update.

4. Benefits of Component-Based Architecture

4.1 Code Reusability

A component can be created once and reused wherever the same UI pattern is needed. For example, a product card component can display many different products by receiving different props.

4.2 Easier Maintenance

When a component has a clear responsibility, developers can often update that component without rewriting the entire application. For example, changing the layout of a product card can be done in the ProductCard component.

4.3 Improved Readability

Breaking a large screen into smaller components makes the code easier to understand. Component names can describe the purpose of each part of the interface.

4.4 Easier Testing

Small components with well-defined inputs and behavior are easier to test individually. Developers can verify that a component displays the correct data or responds properly to interactions.

4.5 Better Team Collaboration

Different developers can work on separate components or feature areas when interfaces and responsibilities are clearly defined. This can reduce conflicts and simplify collaboration.

4.6 Consistent User Experience

Reusable components help maintain consistent layouts, typography, spacing, and interaction patterns across an application.

5. Understanding Component Hierarchy

Components are commonly arranged in a parent-child hierarchy. A parent component can render one or more child components, and those child components can render additional components.

Consider a mobile shopping application with this hierarchy:

App
├── HomeScreen
│   ├── Header
│   ├── SearchBar
│   ├── ProductList
│   │   ├── ProductCard
│   │   ├── ProductCard
│   │   └── ProductCard
│   └── BottomNavigation
└── CartScreen

In this structure, App is the root component. HomeScreen organizes the main shopping screen, while ProductList renders multiple ProductCard instances.

5.1 Parent Components

A parent component renders or contains other components. It can provide data through props and organize the overall layout.

5.2 Child Components

A child component is rendered by another component. It may receive data or callback functions from its parent through props.

5.3 Root Component

The root component is the top-level component from which the application's component tree begins. In a React Native application, the root component is connected to the app entry point.

6. Introduction to JSX

JSX stands for JavaScript XML. It is a syntax extension that allows developers to write markup-like structures inside JavaScript or TypeScript. React tooling transforms JSX into calls that create React elements.

JSX makes component layouts easier to read because the UI structure is written close to the logic that describes it.

6.1 Basic JSX Example

function Greeting() {
  const name = 'Alex';

  return <h1>Hello, {name}!</h1>;
}

This is a React web example. Curly braces allow JavaScript expressions to be included inside JSX.

6.2 JSX in React Native

import React from 'react';
import { View, Text } from 'react-native';

function Greeting() {
  const name = 'Alex';

  return (
    <View>
      <Text>Hello, {name}!</Text>
    </View>
  );
}

export default Greeting;

In this example, View provides a container and Text displays text on the screen.

6.3 Important JSX Rules

  • Return a single parent element, or use a React Fragment where appropriate.
  • Close tags properly, including self-closing elements.
  • Use curly braces to include JavaScript expressions.
  • Use React Native components such as View and Text for mobile UI.
  • Use className for CSS classes in common React web setups, but use the style prop for React Native styling.
  • Use appropriate component names and keep JSX readable.

7. Creating Your First React Native Component

To create a React Native component, define a function that returns React Native elements. You can then export the component and use it in another component.

7.1 Example: Welcome Screen

import React from 'react';
import { View, Text, StyleSheet } from 'react-native';

function WelcomeScreen() {
  return (
    <View style={styles.container}>
      <Text style={styles.title}>Welcome to My App</Text>
      <Text style={styles.subtitle}>
        Learn React Native step by step.
      </Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    padding: 20,
    backgroundColor: '#f5f5f5',
  },
  title: {
    fontSize: 24,
    fontWeight: 'bold',
    marginBottom: 10,
  },
  subtitle: {
    fontSize: 16,
    textAlign: 'center',
  },
});

export default WelcomeScreen;

7.2 Explanation

  • import React from 'react' imports React. Depending on the project's tooling, an explicit React import may not be required for JSX, but it remains common in examples.
  • View creates a layout container.
  • Text displays text content.
  • StyleSheet.create() organizes style definitions.
  • flex: 1 allows the container to occupy available space in its parent.
  • justifyContent: 'center' aligns children along the main axis.
  • alignItems: 'center' aligns children along the cross axis.
  • export default WelcomeScreen makes the component available for import elsewhere.

8. Understanding Props

Props, short for properties, are inputs passed from a parent component to a child component. They allow a component to be configured with different data without changing its internal implementation.

Props are read-only from the receiving component's perspective. A component should not directly modify the props it receives.

8.1 Example of Props

import React from 'react';
import { View, Text } from 'react-native';

function UserCard({ name, role }) {
  return (
    <View>
      <Text>Name: {name}</Text>
      <Text>Role: {role}</Text>
    </View>
  );
}

function App() {
  return (
    <View>
      <UserCard name="Asha" role="Developer" />
      <UserCard name="Rahul" role="Designer" />
    </View>
  );
}

export default App;

8.2 How Props Work

  1. The parent component renders UserCard.
  2. The parent passes values through the name and role props.
  3. The child component receives those values through its function parameters.
  4. The child renders the supplied values.
  5. The same component can display different users without duplicating its implementation.

8.3 Benefits of Props

  • Allow components to display dynamic content.
  • Encourage code reuse.
  • Make data flow between components explicit.
  • Allow parents to configure child component behavior through values and callbacks.

9. Component Composition

Component composition means building a larger interface by combining smaller components. Instead of making one component responsible for everything, developers divide the UI into logical parts.

9.1 Example: Profile Screen

import React from 'react';
import { View, Text } from 'react-native';

function ProfileHeader({ name }) {
  return <Text>Profile: {name}</Text>;
}

function ProfileDetails({ email }) {
  return <Text>Email: {email}</Text>;
}

function ProfileScreen() {
  return (
    <View>
      <ProfileHeader name="Asha" />
      <ProfileDetails email="[email protected]" />
    </View>
  );
}

export default ProfileScreen;

The ProfileScreen combines two smaller components. Each child has a focused responsibility, which makes the screen easier to maintain and extend.

9.2 Good Composition Practices

  • Divide components according to clear UI or functional responsibilities.
  • Give components meaningful names.
  • Keep props clear and limited to the data the component needs.
  • Avoid creating a separate component for every tiny expression unless doing so improves clarity or reuse.
  • Prefer composition over a single component containing unrelated UI logic.

10. Introduction to State

State represents data that can change while a component is being used. When state is updated through React's supported mechanisms, React can render the component again to reflect the new value.

For function components, the useState hook is commonly used to manage local state.

10.1 Example: Counter Component

import React, { useState } from 'react';
import { View, Text, Pressable, StyleSheet } from 'react-native';

function Counter() {
  const [count, setCount] = useState(0);

  return (
    <View style={styles.container}>
      <Text>Count: {count}</Text>
      <Pressable
        style={styles.button}
        onPress={() => setCount(previous => previous + 1)}
      >
        <Text style={styles.buttonText}>Increase</Text>
      </Pressable>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    padding: 20,
    alignItems: 'center',
  },
  button: {
    marginTop: 12,
    padding: 12,
    backgroundColor: '#2563eb',
    borderRadius: 6,
  },
  buttonText: {
    color: '#ffffff',
  },
});

export default Counter;

10.2 Explanation

  • useState(0) initializes the counter to zero.
  • count stores the current state value.
  • setCount requests a state update.
  • onPress handles the user's press interaction.
  • The functional updater receives the previous value and returns the next value.
  • React renders the updated count when the state changes.

10.3 Props vs State

Basis Props State
Purpose Pass data into a component. Store data managed by a component or its state owner.
Who controls it? Usually the parent component. The component or state owner updates it through React APIs.
Mutability Read-only to the receiving component. Updated through a setter such as setCount.
Typical Use Names, labels, images, configuration, callbacks. Form input, toggles, counters, loading status.

11. Types of Components in React

11.1 Function Components

Function components are JavaScript or TypeScript functions that return React elements. They are the standard approach for writing modern React components and can use hooks to manage state and other React features.

function Greeting() {
  return <Text>Hello!</Text>;
}

This simplified example assumes that Text has been imported from React Native.

11.2 Class Components

Class components are an older component style that uses JavaScript classes and lifecycle methods. They are still supported, but function components with hooks are generally preferred for new code.

import React from 'react';
import { Text } from 'react-native';

class Greeting extends React.Component {
  render() {
    return <Text>Hello from a class component!</Text>;
  }
}

export default Greeting;

11.3 Presentational Components

Presentational components focus primarily on displaying UI. They often receive values through props and may be reused in multiple screens.

Examples include buttons, badges, product cards, and profile headers.

11.4 Container or Screen Components

Container components or screen components often coordinate data, state, events, and child components. This is a design pattern rather than a special React component type.

For example, a ProductScreen may coordinate a product list, search input, loading indicator, and product details.

12. Understanding the Virtual DOM and Rendering

In React web applications, the DOM (Document Object Model) represents the web page's structure. React creates an in-memory description of the UI and compares successive render results to determine which changes are needed in the rendered output.

This comparison process is often discussed using the term reconciliation. React determines the necessary updates rather than requiring developers to manually change DOM elements for every state change.

React Native uses React's rendering and reconciliation model too, but it renders through React Native's platform-specific infrastructure rather than the browser DOM. Therefore, it is more accurate to discuss React's rendering model separately from the browser DOM.

12.1 Why Rendering Matters

  • Developers describe what the UI should look like for the current props and state.
  • When relevant data changes, React can render the component again.
  • React reconciles the resulting element tree with the previous one.
  • The renderer applies the necessary updates to the interface.

12.2 Important Note

Not every render means every visible element is recreated from scratch. React can reuse existing structures and apply targeted updates. Developers should focus on correct state and component design before attempting performance optimizations.

13. How React Native Applications Are Structured

A React Native project commonly contains an entry point, application component, screen components, reusable UI components, assets, and supporting logic.

Example project structure:

MyReactNativeApp/
├── App.js
├── src/
│   ├── components/
│   │   ├── Header.js
│   │   └── UserCard.js
│   ├── screens/
│   │   ├── HomeScreen.js
│   │   └── ProfileScreen.js
│   ├── navigation/
│   │   └── AppNavigator.js
│   └── utils/
│       └── helpers.js
├── assets/
└── package.json

This is an illustrative structure. Actual project organization depends on the tools, team conventions, and application size.

13.1 App.js

The App.js file commonly defines the main application component or imports it from another file. It acts as a central place to assemble top-level UI or navigation.

13.2 Components Folder

The components folder commonly contains reusable UI elements such as headers, buttons, cards, form fields, and list items.

13.3 Screens Folder

The screens folder commonly contains full application screens, such as HomeScreen, LoginScreen, SettingsScreen, and ProfileScreen.

13.4 Assets Folder

The assets folder can contain images, icons, fonts, and other resources used by the application.

14. Building a Reusable User Card

One of the best ways to understand component-based architecture is to create a reusable component and display it with different data.

14.1 UserCard.js

import React from 'react';
import { View, Text, StyleSheet } from 'react-native';

function UserCard({ name, designation }) {
  return (
    <View style={styles.card}>
      <Text style={styles.name}>{name}</Text>
      <Text style={styles.designation}>{designation}</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  card: {
    padding: 16,
    marginVertical: 8,
    marginHorizontal: 16,
    backgroundColor: '#ffffff',
    borderRadius: 8,
    elevation: 2,
  },
  name: {
    fontSize: 18,
    fontWeight: 'bold',
  },
  designation: {
    marginTop: 4,
    fontSize: 14,
    color: '#555555',
  },
});

export default UserCard;

14.2 App.js

import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import UserCard from './src/components/UserCard';

function App() {
  return (
    <View style={styles.container}>
      <Text style={styles.heading}>Our Team</Text>
      <UserCard name="Asha Sharma" designation="React Native Developer" />
      <UserCard name="Rahul Mehta" designation="UI Designer" />
      <UserCard name="Priya Singh" designation="Project Manager" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    paddingTop: 40,
    backgroundColor: '#f3f4f6',
  },
  heading: {
    margin: 16,
    fontSize: 24,
    fontWeight: 'bold',
  },
});

export default App;

14.3 Project Explanation

  1. The UserCard component is defined in its own file.
  2. The component receives name and designation as props.
  3. The App component imports and renders UserCard three times.
  4. Each instance receives different values.
  5. The UI stays consistent because all cards use the same component implementation.

Make sure the import path matches your project's actual folder structure.

15. Rendering Lists of Components

Many applications display collections of information, such as users, products, tasks, or messages. React commonly uses JavaScript's map() method to convert an array into a list of components.

15.1 Example: Displaying a User List

import React from 'react';
import { View, Text } from 'react-native';

const users = [
  { id: '1', name: 'Asha' },
  { id: '2', name: 'Rahul' },
  { id: '3', name: 'Priya' },
];

function UserList() {
  return (
    <View>
      {users.map(user => (
        <Text key={user.id}>{user.name}</Text>
      ))}
    </View>
  );
}

export default UserList;

15.2 Why Are Keys Important?

The key prop helps React identify list items between renders. Stable, unique identifiers are preferred because they help React associate items with their previous instances when a list changes.

  • Use a unique ID from the data whenever possible.
  • Avoid duplicate keys among sibling elements.
  • Avoid array indexes as keys when items can be inserted, removed, or reordered.
  • Remember that key is used by React and is not passed to the component as a normal prop.

16. Handling User Interactions

Components can respond to user actions through event-handler props. In React Native, common interactions include pressing a button, entering text, selecting an item, or toggling a control.

16.1 Example: Pressable Component

import React from 'react';
import { View, Text, Pressable, Alert } from 'react-native';

function ActionButton() {
  return (
    <View>
      <Pressable
        onPress={() => Alert.alert('Success', 'Button pressed!')}
      >
        <Text>Click Me</Text>
      </Pressable>
    </View>
  );
}

export default ActionButton;

The onPress handler runs when the user presses the component. This example uses Alert.alert() to display a native alert.

16.2 Common Interaction Components

Component Purpose
Pressable Provides a flexible way to respond to press interactions.
TextInput Accepts text entered by the user.
Switch Provides an on/off control.
ScrollView Provides a scrollable container for content.
FlatList Renders lists efficiently, especially for larger collections.
Image Displays images.

17. Styling React Native Components

React Native uses JavaScript objects for styles. Although many style property names resemble CSS, React Native does not use standard browser CSS files for ordinary component styling.

17.1 Inline Style Example

import React from 'react';
import { View, Text } from 'react-native';

function StyledMessage() {
  return (
    <View style={{ padding: 20, backgroundColor: '#e5e7eb' }}>
      <Text style={{ fontSize: 20, fontWeight: 'bold' }}>
        Welcome!
      </Text>
    </View>
  );
}

export default StyledMessage;

17.2 StyleSheet Example

import React from 'react';
import { View, Text, StyleSheet } from 'react-native';

function StyledMessage() {
  return (
    <View style={styles.container}>
      <Text style={styles.title}>Welcome!</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    padding: 20,
    backgroundColor: '#e5e7eb',
  },
  title: {
    fontSize: 20,
    fontWeight: 'bold',
  },
});

export default StyledMessage;

Using StyleSheet.create() can make styles easier to organize and reuse. Keep style definitions readable and group related styles together.

18. Component Lifecycle and Hooks Overview

Components render in response to their inputs and state. React also provides mechanisms for handling work associated with rendering, updates, and cleanup.

Function components commonly use hooks for these tasks.

18.1 useState

The useState hook stores local state that can change over time.

const [isVisible, setIsVisible] = useState(true);

18.2 useEffect

The useEffect hook is used for synchronizing a component with external systems, such as subscriptions, timers, or network requests. Effects should include appropriate cleanup when required.

import React, { useEffect } from 'react';

useEffect(() => {
  // Synchronize with an external system here.
  return () => {
    // Clean up the synchronization if needed.
  };
}, []);

This snippet illustrates the structure of an effect and is intended to be used inside a function component. The empty dependency array means the effect is set up after the initial mount and cleaned up when the component is removed, subject to React's development behavior and lifecycle semantics.

18.3 useContext

The useContext hook allows components to read values from a React context. It can be useful for shared information such as theme settings or authenticated-user data when passing props through many layers would be inconvenient.

18.4 Rules of Hooks

  • Call hooks at the top level of a function component or a custom hook.
  • Do not call hooks inside loops, conditions, or nested callbacks.
  • Use hooks only in supported React component or custom-hook contexts.
  • Declare dependencies correctly when using effects and memoization hooks.

19. Best Practices for Component-Based Development

  • Keep components focused: Each component should have a clear purpose.
  • Use meaningful names: Names such as ProductCard or ProfileHeader communicate intent.
  • Reuse thoughtfully: Extract common UI when it improves consistency or maintainability.
  • Keep data flow clear: Use props to pass information and callbacks between components.
  • Do not mutate props or state directly: Use React's state-update mechanisms.
  • Separate concerns: Keep reusable UI, screen composition, data access, and utilities organized appropriately.
  • Use stable keys: Provide stable keys when rendering lists.
  • Handle empty and error states: Make components resilient when data is missing or a request fails.
  • Optimize only when needed: Measure performance before introducing complex memoization.
  • Use consistent styling: Share design patterns and avoid unnecessary duplication.
  • Test important behavior: Verify rendering, user interactions, and edge cases.
  • Keep accessibility in mind: Provide appropriate labels and accessible interaction behavior for mobile users.

20. Common Mistakes and Troubleshooting

Problem Possible Cause Solution
Component does not render Incorrect import, export, or component usage. Check the component name, export statement, and import path.
Text is not displayed correctly Text content is not wrapped in a React Native Text component. Use Text to display textual content.
State does not update as expected State is being mutated directly or the update logic is incorrect. Use the setter returned by the state hook.
Props appear undefined The parent did not pass the expected prop or the names do not match. Check the prop names and component parameters.
List displays warnings Items are missing unique keys. Add a stable, unique key to each list item.
Styles do not apply Incorrect property names, invalid values, or incorrect style references. Review the React Native styling API and the styles object.
Component is too large Too many unrelated responsibilities in one component. Split the interface into focused, reusable child components.
Repeated UI looks inconsistent Similar elements are implemented separately. Extract shared UI into reusable components.
Unexpected repeated side effects Effect dependencies or cleanup are incorrect, or development checks expose setup issues. Review dependencies, cleanup logic, and React development behavior.

21. Mini Project: Team Directory App

Build a simple team directory screen to practise React Native components, props, lists, and styling.

21.1 Project Requirements

  • Create a screen title named Team Directory.
  • Display a list of team members.
  • Show each member's name and job role.
  • Use one reusable TeamMemberCard component.
  • Pass each person's details through props.
  • Render the collection using map() or FlatList.
  • Use consistent spacing, typography, and card styling.
  • Test the layout on an Android or iOS simulator or device.

21.2 Suggested Data

const teamMembers = [
  { id: '1', name: 'Asha Sharma', role: 'Developer' },
  { id: '2', name: 'Rahul Mehta', role: 'Designer' },
  { id: '3', name: 'Priya Singh', role: 'Project Manager' },
];

21.3 Suggested Component Structure

App
└── TeamDirectoryScreen
    ├── ScreenTitle
    └── TeamMemberList
        ├── TeamMemberCard
        ├── TeamMemberCard
        └── TeamMemberCard

21.4 Learning Outcomes

After completing the project, learners should be able to create reusable components, pass data through props, render collections, apply styles, and organize a screen using component composition.

22. Practice Exercises

  1. Create a component named GreetingScreen that displays a welcome message.
  2. Create a reusable ProductCard component with product name and price props.
  3. Render three product cards with different data.
  4. Create a ProfileCard component that accepts name, email, and role.
  5. Build a counter component using useState.
  6. Display an array of tasks using map() and unique keys.
  7. Create a parent component that combines a header, content section, and footer.
  8. Move a repeated UI section into a separate component file and import it into the screen.
  9. Apply styles using StyleSheet.create().
  10. Explain the difference between props and state with a practical example.

23. Interview Questions and Answers

Q1. What is React?

Answer: React is a JavaScript library for building user interfaces using reusable components and a declarative programming model.

Q2. What is React Native?

Answer: React Native is a framework for building native mobile applications using React concepts and JavaScript or TypeScript.

Q3. What is component-based architecture?

Answer: It is an approach in which an application is divided into smaller, reusable, and focused components that combine to form the complete interface.

Q4. What is a React component?

Answer: A React component is a reusable unit of UI, commonly defined as a JavaScript or TypeScript function that returns React elements.

Q5. What is JSX?

Answer: JSX is a syntax extension that allows developers to write markup-like UI structures within JavaScript or TypeScript.

Q6. What are props?

Answer: Props are read-only inputs passed from a parent component to a child component.

Q7. What is state?

Answer: State is data managed by a component or state owner that can change over time and trigger updates to the rendered UI.

Q8. What is the difference between props and state?

Answer: Props are supplied to a component by its parent, while state is managed through React state mechanisms by the component or the state owner.

Q9. What is component composition?

Answer: Component composition is the practice of combining smaller components to create larger UI structures.

Q10. Why is component reusability important?

Answer: It reduces duplication, supports consistency, and makes updates easier to maintain across an application.

Q11. What is the purpose of useState?

Answer: The useState hook allows function components to store and update local state.

Q12. What is the purpose of keys in React lists?

Answer: Keys help React identify list items between renders so it can reconcile changes correctly.

Q13. What is the difference between React and React Native?

Answer: React is commonly used to build web interfaces, while React Native uses React concepts to build native mobile applications with platform-specific UI components.

Q14. What is a parent component?

Answer: A parent component renders or contains child components and can pass data and callbacks to them through props.

Q15. What is the purpose of StyleSheet.create()?

Answer: It provides a structured way to define and organize React Native style objects.

24. Quick Revision Checklist

  • Understand the purpose of React and React Native.
  • Explain component-based architecture.
  • Identify parent, child, and root components.
  • Understand JSX syntax and its basic rules.
  • Create a React Native function component.
  • Pass data through props.
  • Manage changing values with useState.
  • Combine components through composition.
  • Render arrays using map() or FlatList.
  • Use stable keys for list items.
  • Handle interactions with event props such as onPress.
  • Apply styles with React Native style objects.
  • Organize components into reusable files and folders.
  • Understand the basic rendering and reconciliation model.
  • Identify and troubleshoot common component errors.

25. Conclusion

React provides a component-based approach to building user interfaces, while React Native applies React concepts to native mobile application development. Understanding components, JSX, props, state, composition, and rendering is essential for creating maintainable applications.

By dividing a screen into small, reusable components, developers can reduce duplication, improve consistency, simplify testing, and make their applications easier to extend. Practising with reusable cards, lists, profile screens, and small mobile projects builds a strong foundation for more advanced React Native topics such as navigation, API integration, forms, local storage, and application architecture.

Continue Learning: Explore the React Native Training Course, visit the JustAcademy website, or register for a course demo.

whatsapp